home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4527 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: columba.udac.uu.se!news
  2. From: Enrico Savazzi <enrico.savazzi@pal.uu.se>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to copy from Array to Array ?
  5. Date: Mon, 05 Feb 1996 17:14:29 +0100
  6. Organization: Uppsala University
  7. Message-ID: <31162CE5.43C0@pal.uu.se>
  8. References: <4f3ec3$3vp5@unix1.sncc.lsu.edu>
  9. NNTP-Posting-Host: esavazzi.pal.uu.se
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (WinNT; I)
  14.  
  15. Rajabhushan Cherukuri wrote:
  16. > Hello Everybody:
  17. >         I have a simple question on using Arrays and Pointers. Let's say
  18. > that i have two arrays declared as,
  19. >           double Array1[15000], and char Array2[15000].
  20. >     How do i sequentially copy elements from Array1 to Array2 using "sprintf"
  21. > and "pointers" and how i can print the values in Array2. Any suggestions
  22. > will be appreciated.
  23. > RAJABHUSHAN CHERUKURI (RAJ)
  24. > LOUISIANA STATE UNIVERSITY
  25. > garaja@unix1.sncc.lsu.edu
  26.  
  27. I have not tried this, but it is what I would do to develop the 
  28. piece of software you need:
  29.  
  30. 1-use sprintf() to print a double to a temporary buffer
  31. 2-determine the length of the string in the buffer (with 
  32. strlen())
  33. 3-Copy the string bytes to Array2. Keep a pointer that tells you 
  34. the last used byte in Array2.
  35. 4-Append to the used portion of Array2 a character to indicate 
  36. the end of a string containing the double value. Increment by 
  37. one the pointer to last-used-byte.
  38. 5-repeat until you have all the doubles lined up in Array2.
  39.  
  40. To print, parse Array2 and isolate one by one all the substrings 
  41. terminated by the character you used to separate the values. As 
  42. a separator character, you can use any character except 0-9, e, 
  43. E, .(point), +, - (i.e., all characters that can be part of a 
  44. double representation). Do not use '\0' (null), because this is 
  45. the end-of-string marker, and you would be unable to use 
  46. standard string functions after the first null.
  47.  
  48. E. Savazzi
  49.